package com.itheima.pattern.singleton.demo7;

import java.io.*;

public class Client {
    public static void main(String[] args)  throws IOException, ClassNotFoundException {
       // writeObject2File();
        readObject2File();
        readObject2File();
        System.out.println(2);
        System.out.println(333);
    }

    public static void writeObject2File() throws IOException {
        // 获取singleton对象
        Singleton instance = Singleton.getInstance();
        // 创建对象输出流输出对象
        ObjectOutputStream ois = new ObjectOutputStream(new FileOutputStream("D://a.txt"));
        ois.writeObject(instance);
        ois.close();
    }

    public static void readObject2File() throws IOException, ClassNotFoundException {
        ObjectInputStream is = new ObjectInputStream(new FileInputStream("D://a.txt"));
        Singleton o = (Singleton)is.readObject();
        System.out.println(o);
        is.close();
    }
}
